Back to Documentation

UDP Provider

Fast connectionless communication for UTCP

The UDP provider enables UTCP to communicate with services over UDP (User Datagram Protocol), providing fast, connectionless communication with minimal overhead. This provider is ideal for applications requiring low latency, real-time data transmission, or fire-and-forget messaging.

Configuration

UDP providers are configured using the following JSON structure:

{
  "name": "udp_service",
  "provider_type": "udp",
  "host": "api.example.com",
  "port": 5000,
  "timeout": 5000,
  "max_retries": 3,
  "encoding": "utf-8"
}

Configuration Fields

Field Required Description
name Yes Unique identifier for the provider
provider_type Yes Must be set to "udp"
host Yes Hostname or IP address of the UDP server
port Yes Port number of the UDP server
timeout No Response timeout in milliseconds (default: 5000)
max_retries No Maximum number of retry attempts (default: 3)
encoding No Text encoding for string data (default: "utf-8")
buffer_size No Buffer size for receiving data (default: 1024)

UDP Characteristics

UDP is a connectionless protocol with specific characteristics that affect how tools are implemented:

Advantages

  • Low latency - no connection establishment required
  • Minimal overhead - simple packet structure
  • Suitable for real-time applications
  • Supports broadcasting and multicasting

Limitations

  • No guarantee of delivery
  • No guarantee of order
  • No automatic error correction
  • Limited packet size (typically 65,507 bytes)

Tool Discovery

Since UDP is connectionless and doesn't support standardized discovery, UTCP tools using UDP providers typically rely on:

{
  "name": "udp_service",
  "provider_type": "udp",
  "host": "api.example.com",
  "port": 5000,
  "discovery_url": "https://api.example.com/utcp"
}

Examples

DNS-like Service

{
  "name": "dns_service",
  "provider_type": "udp",
  "host": "dns.example.com",
  "port": 53,
  "timeout": 3000,
  "max_retries": 2
}

Game Server Communication

{
  "name": "game_server",
  "provider_type": "udp",
  "host": "game.example.com",
  "port": 7777,
  "timeout": 1000,
  "max_retries": 1,
  "buffer_size": 2048
}

IoT Sensor Data

{
  "name": "sensor_data",
  "provider_type": "udp",
  "host": "sensors.example.com",
  "port": 1234,
  "timeout": 2000,
  "max_retries": 0,
  "encoding": "binary"
}

Best Practices

Reliability

  • Implement retry logic with exponential backoff
  • Use sequence numbers for duplicate detection
  • Keep message sizes small to avoid fragmentation
  • Implement application-level acknowledgments if needed

Performance

  • Use short timeouts for real-time applications
  • Minimize the number of round trips
  • Consider using binary protocols for efficiency
  • Implement proper error handling for network issues

Security

  • Validate all incoming data thoroughly
  • Implement rate limiting to prevent DoS attacks
  • Use encryption for sensitive data transmission
  • Consider using DTLS for secure UDP communication

© 2024 Universal Tool Calling Protocol. All rights reserved.